const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    // await this.getOrderData()
    this.setData({
      isShow: app.isShowTotal,
      shopName: app.shopName
    })
  },

  onShow: async function (options) {
    await this.getOrderData()
  },

  async getOrderData(){
    let userinfo = wx.getStorageSync('logininfo')
    
    if (!userinfo.openid) {
      wx.showModal({
        content: '请登录',
        confirmColor: app.PCOLOR,
        success: res => {
          if (res.confirm) {
            wx.switchTab({
              url: '/pages/mine/mine',
            })
          }
        }
      })
      return
    }
    console.log(userinfo);
    
    const res = await app._http({
      url: 'order/list',
      data: {
        openid: userinfo.openid,
        store: app.store
      }
    })
    this.setData({
      orders: res.data.data
    })
  },

  gotoDetail(e){
    console.log(e, 'eee');
    
    const { id } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/orderdetail/orderdetail?id=' + id
    })
  },
})